/**
 *
 * @author ilya portnyagin iportnyagin@gmail.com
 */

package ru.portnyagin.helpdeskru.model;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@Table(name = "file")
public class FileHD implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID")
    private Long id;
   
    @Column(name = "NAME")
    private String name;
    
    @Lob
    @Column(name = "CONTENT")
    private byte[] content;        

    @JoinColumn(name = "REQUEST", referencedColumnName = "ID")
    @ManyToOne(fetch = FetchType.LAZY)
    private Request request;
        
    @JoinColumn(name = "UPLOADED_BY", referencedColumnName = "ID")
    @ManyToOne(fetch = FetchType.LAZY)
    private UserHD uploadedBy;
        
    @Column(name = "UPLOADED_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    private Date uploadedDate;

    
    public FileHD() {
    }

    public FileHD(Long id) {
        this.id = id;        
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public byte[] getContent() {
        return content;
    }

    public void setContent(byte[] content) {
        this.content = content;
    }

    public Request getRequest() {
        return request;
    }

    public void setRequest(Request request) {
        this.request = request;
    }

    public UserHD getUploadedBy() {
        return uploadedBy;
    }

    public void setUploadedBy(UserHD uploadedBy) {
        this.uploadedBy = uploadedBy;
    }

    public Date getUploadedDate() {
        return uploadedDate;
    }

    public void setUploadedDate(Date uploadedDate) {
        this.uploadedDate = uploadedDate;
    }

    

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof FileHD)) {
            return false;
        }
        FileHD other = (FileHD) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return name;
    }
    
}
